﻿using B.S.DataBase.MyProject.Domain.BOM;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Write.API.Applicantions.Command.BOMCommand;

namespace T.E.ERP.Write.API.Applicantions.CommandHandler.BOMCommandHandler
{
    public class UpdateProcessCommandHandler : IRequestHandler<UpdateProcessCommand, APIResult<int>>
    {
        private readonly IBaseRepository<ProcessInfo> proRep;
        public UpdateProcessCommandHandler(IBaseRepository<ProcessInfo> proRep)
        {
            this.proRep = proRep;
        }
        public Task<APIResult<int>> Handle(UpdateProcessCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var prolist = proRep.GetAll().Result.Where(x => x.ProcessId == request.ProcessId).FirstOrDefault();
            prolist.ProcessCode=request.ProcessCode;
            prolist.StepName = request.StepName;
            prolist.OrderCode = request.OrderCode;
            prolist.ProcessName = request.ProcessName;
            prolist.ResName = request.ResName;
            prolist.DepName = request.DepName;
            prolist.Num=request.Num;

            var res = proRep.Update(prolist).Result;
            if (res>0)
            {
                result.Code = APIEnum.修改成功;
                result.Msg = APIEnum.修改成功.ToString();
                result.data = res;
            }
            else
            {
                result.Code = APIEnum.修改失败;
                result.Msg = APIEnum.修改失败.ToString();
                result.data = res;
            }
            return Task.FromResult(result);
        }
    }
}
